package cn.edu.nuc.crm.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.nuc.crm.dao.ManagerMapper;
import cn.edu.nuc.crm.dto.PageInfo;
import cn.edu.nuc.crm.entity.Manager;
import cn.edu.nuc.crm.service.interfaces.ManagerService;
@Service
public class ManagerServiceImpl implements ManagerService {
	@Autowired
	private ManagerMapper managerMapper;
	@Override
	public Manager login(String managername, String managerpassword) {		
		Manager manager = managerMapper.findByManager(managername);
		System.out.println(manager);
		if( manager == null){
			throw new RuntimeException("用户名错误");
		}else if( !managerpassword.equals(manager.getManagerpassword())){
			throw new RuntimeException("密码错误");
		}
		return manager;
	}
	@Override
	public List<Manager> manager() {
		List<Manager> manager = new ArrayList<Manager>();
		manager = managerMapper.manager();
		return manager;
	}
	@Override
	public PageInfo pi(int current) {
		PageInfo pi = new PageInfo(current);
		int count = managerMapper.count();
		pi.setCount(count);
		List<Manager> findByid=managerMapper.findByid(pi.getStart(), pi.getOffset());
		System.out.println("总的记录数:"+count+"--"+pi);
		pi.setList(findByid);
		return pi;
	}
	@Override
	public int deleteByPrimaryKey(Integer managerid) {
		int result=managerMapper.deleteByPrimaryKey(managerid);
		return result;
	}

}
